//
//  MyFamilyTroViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/7/20.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "MyFamilyTroViewController.h"
#import "BabyViewController.h"
#import "SettingViewController.h"
#import "MessageViewController.h"
#import "AddBabyViewController.h"
#import "DoorTeachViewController.h"
#import "EvaluateViewController.h"
#import "SameCityViewController.h"
#import "HomePaternityViewController.h"
#import "BabyManager.h"

@interface MyFamilyTroViewController ()

@end

@implementation MyFamilyTroViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏头文字
    self.navigationItem.title = @"同城亲子";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ffb750" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]
                                 initWithTitle:@"宝宝"
                                 style:UIBarButtonItemStylePlain
                                 target:self
                                 action:@selector(turntoBaby)];
    [rightBtn setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    //隐藏分割线
    _tableView.separatorStyle = UITableViewCellEditingStyleNone;
    _tableView.backgroundColor = UIColorWithRGBA(232, 232, 232, 1);
    [self.view addSubview:_tableView];
    _babyNameArray = [NSMutableArray array];

    
//
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString *ID = [user objectForKey:@"ID"];
//    NSDictionary *param = @{@"userId": @"1"};
//    [UserDAL getHomeDataWithParams: param withBlock:^(NSArray *data, NSError *error) {
//        
//        
//        if (data) {
//            ////NSLog(@"=========================%@",data);
//            for (NSDictionary *myDic in data) {
//                
//                
//                NSString * name = [myDic objectForKey:@"babyName"];
//                [_babyNameArray addObject:name];
//                //                [_babyTimeArray addObject:myDic[@"babyAge"]];
//                //                [_babyIDArray addObject:myDic[@"ID"]];
//                //                [_babyWt addObject:myDic[@"babyHeight"]];
//                //                [_babyHt addObject:myDic[@"babyWeight"]];
//                
//                //                ////NSLog(@"%@",_babyNameArray);
//                ////NSLog(@"%@呵呵呵",_babyNameArray);
//                
//                
//            }
//            
//            [_tableView reloadData];
//            
//        }
//        else
//        {
//            
//            
//            
//        }
//        
//        //        [_tableView reloadData];
//        
//        
//    }];

    
    
    
    
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    
    
    
    
}


-(void)turntoBaby{
    
    
    
    
    
}

#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
        
    }else if (section == 1){
        
        return 3;
    }else{
        
        return 2;
    }
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 1) {
        return 11;
    } else {
        return 0;
        
    }
    
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *NOTIFY = @"cell";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
        
        
        ////NSLog(@"%@呵",_babyNameArray);

        
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        NSString *ID = [user objectForKey:@"ID"];
        NSDictionary *param = @{@"userId": @"1"};
        [UserDAL getHomeDataWithParams: param withBlock:^(NSDictionary *data, NSError *error) {
            if (data) {
                ////NSLog(@"=========================%@",data);
                
                NSArray *dataList = data[@"dataList"];

                for (NSDictionary *myDic in dataList) {
                    NSString * name = [myDic objectForKey:@"babyName"];
                    [_babyNameArray addObject:name];
                    //                [_babyTimeArray addObject:myDic[@"babyAge"]];
                    //                [_babyIDArray addObject:myDic[@"ID"]];
                    //                [_babyWt addObject:myDic[@"babyHeight"]];
                    //                [_babyHt addObject:myDic[@"babyWeight"]];
                    
                    //                ////NSLog(@"%@",_babyNameArray);
                    ////NSLog(@"%@呵呵呵",_babyNameArray);
                    
                    
                    
                    
                    if (indexPath.section == 0)
                        
                    {
                        
                        
                        _tableView.rowHeight = (76*3+22)/2;
                        UIImageView * image = [[UIImageView alloc]init];
                        image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                        image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                        [cell addSubview:image];
                        
                        
                        UILabel * lab = [[UILabel alloc]init];
                        lab.frame = CGRectMake(70, 98/2, SCREEN_WIDTH-140, 18);
                        lab.text = @"宝宝叫做XXX";
                        lab.font = [UIFont systemFontOfSize:18];
                        lab.textAlignment = NSTextAlignmentCenter;
                        [image addSubview:lab];
                        
                        UILabel * lab1 = [[UILabel alloc]init];
                        lab1.frame = CGRectMake(SCREEN_WIDTH/2-140, (98+76)/2, 140, 11);
                        lab1.text = @"身高：120--130m";
                        lab1.font = [UIFont systemFontOfSize:15];
                        lab1.textAlignment = NSTextAlignmentLeft;
                        [image addSubview:lab1];
                        
                        UILabel * lab2 = [[UILabel alloc]init];
                        lab2.frame = CGRectMake(SCREEN_WIDTH/2+20, (98+76)/2, 140, 11);
                        lab2.text = @"体重：12--15t";
                        lab2.font = [UIFont systemFontOfSize:15];
                        lab2.textAlignment = NSTextAlignmentLeft;
                        [image addSubview:lab2];
                        
                        
                    } else {
                        
                        
                        _tableView.rowHeight = 93/2;
                        if (indexPath.section == 1) {
                            
                            
                            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                            
                            NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"          上门早教",@"          同城解读",@"          户外亲子", nil];
                            cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                            
                            _image = [[UIImageView alloc]init];
                            _image.frame = CGRectMake(13, (93/2-25)/2, 25, 25);
                            _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row+1]];
                            [cell addSubview:_image];
                            
                            _image1 = [[UIImageView alloc]init];
                            _image1.frame = CGRectMake(SCREEN_WIDTH-79/2-25, (93/2-25)/2, 25, 25);
                            _image1.image = [UIImage imageNamed:@"6.png"];
                            [cell addSubview:_image1];
                            
                            
                            UILabel * lab = [[UILabel alloc]init];
                            lab.frame = CGRectMake(0, 0, 25, 25);
                            lab.text = [NSString stringWithFormat:@"%d",indexPath.row*3];
                            lab.textColor = [UIColor whiteColor];
                            lab.font = [UIFont systemFontOfSize:9];
                            lab.textAlignment = NSTextAlignmentCenter;
                            [_image1 addSubview:lab];
                            
                            
                        } else {
                            
                            
                            
                            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                            
                            NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"          消息中心",@"          设置", nil];
                            cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                            
                            _image = [[UIImageView alloc]init];
                            _image.frame = CGRectMake(13, (93/2-25)/2, 25, 25);
                            _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row+4]];
                            [cell addSubview:_image];
                            
                            //            _image1 = [[UIImageView alloc]init];
                            //            _image1.frame = CGRectMake(SCREEN_WIDTH-79/2-25, (93/2-25)/2, 25, 25);
                            //            _image1.image = [UIImage imageNamed:@"6.png"];
                            //            [cell addSubview:_image1];
                            
                            
                            
                        }
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                    }
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                }
                
                [_tableView reloadData];
                
            }
            else
            {
                
                
            }
            
            //        [_tableView reloadData];
            
            
        }];
        
        
        
        
        
        

        
        
    }
    
    
    ////NSLog(@"%@he呵",_babyNameArray);

    
    
    
    
    
    
    
    return cell;
    
    
}
#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
